//
//  DZPrivateSubCatViewController.m
//  DaZhePrivateHomeCuisineClient
//
//  Created by zouzhisheng on 15/2/7.
//  Copyright (c) 2015年 zouzhisheng. All rights reserved.
//

#import "DZPrivateSubCatViewController.h"
#import "DZCategoryInfoModel.h"
#import "DZListTableViewCell.h"
@interface DZPrivateSubCatViewController (){
    NSMutableArray *dataArray;
}

@end

@implementation DZPrivateSubCatViewController

- (void)viewDidLoad {
    [super viewDidLoad];
     dataArray=[NSMutableArray array];
    [self addTitle:self.subTitle];
    [self loadData];
    // Do any additional setup after loading the view.
}
-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
}
-(void)loadData{
    NSDictionary *paramDir=[NSDictionary dictionaryWithObjectsAndKeys:@"list",@"act",self.catid,@"catid", nil];
    [[BaseService shareNetworkService] requestActivityParameters:paramDir DataSouce:self RequestType:Request_DaZheListInfo Block:^(__weak id data, NSError *error) {
        if (!error) {
            DZCategoryInfoModel *model=data;
            if (model.SiFangCaiCategoryInfo.count>0) {
                for (int i=0; i<model.SiFangCaiCategoryInfo.count; i++) {
                    [dataArray addObject:model.SiFangCaiCategoryInfo[i]];
                }
            }
            [self loadSubView];
        }
    }];
}
-(void)loadSubView
{
    [self.view addSubview:self.listView];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(UITableView *)listView
{
    if (!_listView) {
        _listView=[[UITableView alloc] initWithFrame:CGRectMake(0,self.navView.bottom,SCREEN_WIDTH,SYSTEM_VERSION>=7.0?SCREEN_HEIGHT-self.navView.height-49:SCREEN_HEIGHT-self.navView.height-20-49) style:UITableViewStylePlain];
        _listView.delegate=self;
        _listView.dataSource=self;
        _listView.backgroundColor=[UIColor clearColor];
        _listView.separatorStyle=UITableViewCellSeparatorStyleNone;
    }
    return _listView;
}
#pragma mark-UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    id obj=dataArray[indexPath.row];
    if ([obj isKindOfClass:[DZCategoryInfoSubModel class]]) {
        static NSString *cellIdentifier=@"DZListTableViewCell";
        DZListTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
        if (!cell) {
            cell = [[[NSBundle mainBundle] loadNibNamed:@"DZListTableViewCell"  owner:self options:nil] lastObject];
        }
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        [cell loaddata:obj];
        return cell;
    }
    return nil;
}

#pragma mark-UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    id obj=dataArray[indexPath.row];
    if ([obj isKindOfClass:[DZCategoryInfoSubModel class]]) {
        return 90;
    }
    return 0;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    id obj=dataArray[indexPath.row];
    if ([obj isKindOfClass:[DZCategoryInfoSubModel class]]){
        DZCategoryInfoSubModel *model=obj;
        DZPrivateDetailViewController *detailVC=[[DZPrivateDetailViewController alloc] init];
        detailVC.articleid=model.articleid;
        detailVC.subject=model.subject;
        [self.navigationController pushViewController:detailVC animated:YES];
    }
    
}
-(void)tableView:(UITableView*)tableView  willDisplayCell:(UITableViewCell*)cell forRowAtIndexPath:(NSIndexPath*)indexPath
{
    [cell setBackgroundColor:[UIColor clearColor]];
}
-(void)backAction:(UIButton*)bt{
    [self.navigationController popViewControllerAnimated:YES];
}
- (UIView *)viewForLoadAnimationAtService:(RequestType)type{
    return self.view;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
